package com.dingdang.controller;


import com.alibaba.fastjson.JSONObject;
import com.dingdang.data.Result;
import com.dingdang.em.ResultEnum;
import com.dingdang.entity.SeckillCar;
import com.dingdang.mapper.SeckillCarMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 董书乾
 * @since 2021-12-17
 */
@RestController
@RequestMapping("/salesPromotion")
@Api(value = "促销商品的管理")
public class SalesPromotionCarController {
    @Resource
    private SeckillCarMapper seckillCarMapper;

    //    增
    @PostMapping
    @ApiOperation(value = "增加促销商品")
    @ApiImplicitParam(name = "seckillCar", value = "促销车辆的体类", paramType = "body", required = true)
    public Result addPromotionCar(@RequestBody SeckillCar seckillCar) {
        SeckillCar seckillCar1 = JSONObject.parseObject(JSONObject.toJSONString(seckillCar), SeckillCar.class);
        seckillCarMapper.insert(seckillCar);
        return Result.response(ResultEnum.SUCCESS).setData(seckillCar);
    }

    //    删
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除促销商品")
    @ApiImplicitParam(name = "id", value = "主键id", paramType = "path", required = true)
    private Result deletePromotionCar(@PathVariable("id") long id) {
        seckillCarMapper.deleteById(id);
        return Result.response(ResultEnum.SUCCESS);
    }


    //    改
    @PutMapping
    @ApiOperation(value = "修改促销商品")
    @ApiImplicitParam(name = "seckillCar", value = "促销车辆的体类", paramType = "body", required = true)
    private Result deletePromotionCar(@RequestBody SeckillCar seckillCar ) {
        seckillCarMapper.updateById(seckillCar);
        return Result.response(ResultEnum.SUCCESS);
    }
//    查
    @GetMapping
    @ApiOperation(value = "查询促销商品")
    private Result selectPromotionCar() {
        List<SeckillCar> seckillCars = seckillCarMapper.selectList(null);
        return Result.response(ResultEnum.SUCCESS).setData(seckillCars);
    }


}
